<template>
  <view class="updateTel">
    <view class="flex-box border-bottom-box form-item">
      <view>手机号</view>
      <view class="auto-box flex-box left-space">
        <view class="auto-box">
          <input
            placeholder-class="placeholder-box"
            maxlength="11"
            placeholder="请输入手机号"
            type="tel"
            v-model="telInfo.mobile"
          />
        </view>
      </view>
    </view>
    <view class="flex-box border-bottom-box form-item">
      <view>验证码</view>
      <view class="auto-box flex-box left-space">
        <view class="auto-box">
          <input
            placeholder-class="placeholder-box"
            maxlength="11"
            placeholder="请输入短信验证码"
            type="tel"
            v-model="telInfo.code"
          />
        </view>
        <view class="code-box" @tap.stop="getCode">{{ codeText }}</view>
      </view>
    </view>
	<view class="flex-box center-box">
	<view class="btn-box">完成绑定</view>
    </view>
  </view>
</template>

<script setup>
import { ref, onMounted } from "vue";
const telInfo = ref({
  mobile: "",
  code: "",
});
let codeText = ref("获取验证码");
// 计时器
let timer = null;
/**
 * @description 获取验证码
 */
function getCode() {
  if (timer) {
    return
  }
  if (telInfo.value.mobile.length === 11) {
    uni.showToast({
      title: "发送成功",
      icon: "none",
    });
    codeText.value = "60s";
    let time = 60;
    timer = setInterval(() => {
      if (time > 0) {
        codeText.value = time + "s";
        time--;
      } else {
        clearInterval(timer);
        codeText.value = "获取验证码";
        timer = null;
      }
    },1000);
  }
}
/**
 * @description 完成绑定
 */
function handleBind() {
  console.log(telInfo.value);
}
</script>

<style lang="scss" scoped>
.updateTel {
  height: calc(100vh - 152rpx);
  background-color: #fff;
  padding: 32rpx;

  .form-item {
    padding: 20rpx 0;
    font-size: 26rpx;
    color: #000;
    text-align: left;
  }

  .auto-box {
    flex: 1;
  }

  .placeholder-box {
    color: rgba(144, 144, 144);
    font-size: 24rpx;
  }
  .code-box {
    width: 188rpx;
    text-align: center;
    color: #fff;
    font-size: 28rpx;
    height: 50rpx;
    line-height: 50rpx;
    background: rgba(67, 207, 124, 1);
    color: #fff;
    border-radius: 30px;
    margin-left: 40rpx;
  }
  .left-space{
	margin-left: 82rpx;
  }
  .btn-box{
	margin:120rpx;
	padding: 22rpx 0;
	color:#fff;
	font-size: 40rpx;
    background: rgba(67, 207, 124, 1);
	text-align: center;
    flex: 1;
	border-radius: 60rpx;
  }
}
</style>
